package com.weiaibenpao.demo.chislim.ui.activity.me;

import android.os.Bundle;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.weiaibenpao.demo.chislim.R;
import com.weiaibenpao.demo.chislim.base.BaseActivity;
import com.weiaibenpao.demo.chislim.bean.MedalBean;
import com.weiaibenpao.demo.chislim.db.preferences.UserPreferences;
import com.weiaibenpao.demo.chislim.presenter.MedalPresenter;
import com.weiaibenpao.demo.chislim.view.MedalView;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;

public class MedalActivity extends BaseActivity<MedalView, MedalPresenter> implements MedalView {

    @BindView(R.id.medal1)
    ImageView medal1;
    @BindView(R.id.medal2)
    ImageView medal2;
    @BindView(R.id.medal3)
    ImageView medal3;
    @BindView(R.id.medal4)
    ImageView medal4;
    @BindView(R.id.medal5)
    ImageView medal5;
    @BindView(R.id.medal6)
    ImageView medal6;

    UserPreferences userPreferences;

    ArrayList<ImageView> arrayList;

    @Override
    public int setLayoutResourceID() {
        return R.layout.activity_medal;
    }

    @Override
    public void init(Bundle savedInstanceState) {
        userPreferences = UserPreferences.getInstance();
        arrayList = new ArrayList();
        arrayList.add(medal1);
        arrayList.add(medal2);
        arrayList.add(medal3);
        arrayList.add(medal4);
        arrayList.add(medal5);
        arrayList.add(medal6);
        immersionBar
                .statusBarDarkFont(true)
                .statusBarColor(R.color.white)//状态栏颜色，不写默认透明色
                .fitsSystemWindows(true)//解决状态栏和布局重叠问题，任选其一，默认为false，当为true时一定要指定statusBarColor()，不然状态栏为透明色，还有一些重载方法
                .init();

        mPresenter.getMedal(userPreferences.getInt(UserPreferences.USER_ID));
    }

    public void initView(MedalBean medalBean) {
        for (int i = 0; i < medalBean.getBadgeListResult().size(); i++) {
            if (medalBean.getBadgeListResult().get(i).getIsHave().equals("1")) {   //
                Glide.with(this)
                        .load(medalBean.getBadgeListResult().get(i).getBadgeIconUrl())
                        .into(arrayList.get(i));
            } else {
                Glide.with(this)
                        .load(medalBean.getBadgeListResult().get(i).getBadgewhiteIconUrl())
                        .into(arrayList.get(i));
            }
        }
    }

    @Override
    public void medalSuccess(MedalBean medalBean) {
        initView(medalBean);
    }


    @Override
    public MedalPresenter initPresenter() {
        return new MedalPresenter();
    }


    @OnClick(R.id.left_image)
    public void onViewClicked() {
        finish();
    }
}
